library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;


entity comparator is
generic (N:integer:=32);
port (	subtraction	: in   std_logic_vector (N-1 downto 0);
		cmp_need	: in   std_logic_vector (2 downto 0);
		O			: out std_logic_vector (N-1 downto 0)
	);
end comparator;

architecture Behavioral of comparator is

signal temp 	: std_logic_vector (N-1 downto 0) := (others =>'0');
signal sub 	: integer;
begin

process(subtraction,cmp_need,sub,temp)
begin
	
	sub <= to_integer(signed(subtraction));
	temp(N-1 downto 0) <= (others => '0');
	
	if sub = 0 then
		if (cmp_need(0)='1') then	-- <
			temp(0) <= '1';
		else
			temp(0) <= '0';	
		end if;
	end if;
	if sub < 0 then
		if (cmp_need(1)='1') then	-- <
			temp(0) <= '1';
		else
			temp(0) <= '0';	
		end if;
	elsif sub > 0 then
		if (cmp_need(2)='1') then	-- >
			temp(0) <= '1';
		else
			temp(0) <= '0';	
		end if;
	end if;
	
end process;

O<=temp;
end Behavioral;

